package com.niuke.threadlocal;

/**
 * @author John Doe Tang
 * @date 2021年07月05日 22:16
 */
public class ThreadLocalTest {

  private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

  public static void main(String[] args) throws InterruptedException {
    Task task = new Task();

    new Thread(task).start();
    Thread.sleep(10);
    new Thread(task).start();
  }

  static class Task implements Runnable {

    @Override
    public void run() {
      Long result = threadLocal.get();
      if (result == null) {
        threadLocal.set(System.currentTimeMillis());
        System.out.println(Thread.currentThread().getName() + "->" + threadLocal.get());

      }
    }
  }
}


